**********************************************************************
*Pseudo data creation
**********************************************************************
*SBA disaster loan data via FOIA provides lender names, which allow us to match the data with Florida UCC records. Since FOIA data from SBA is confidential, we do not provide this dataset in the replication package. Instead, we provide a pseudo dataset "FOIA_pseudo", where the variables values are replaced with random numbers with same mean and variance. Below is the code to generate the pseudo data.
*Define directory
cap cd "...\Replication pacakage\"

clear all
use year year1 ORIGINAL_APPROVAL_AMOUNT id using FOIA.dta,clear
keep if ORIGINAL_APPROVAL_AMOUNT<=65000
su ORIGINAL_APPROVAL_AMOUNT
*generate random numbers for loan amount with the same mean and variance
egen mean=mean(ORIGINAL_APPROVAL_AMOUNT)
egen sd=sd(ORIGINAL_APPROVAL_AMOUNT)
replace ORIGINAL_APPROVAL_AMOUNT=sd*rnormal()+mean
su ORIGINAL_APPROVAL_AMOUNT

save FOIA_pseudo.dta, replace
**********************************************************************
*Replication code starts here.
**********************************************************************
*Define directory
cap cd "...\Replication pacakage\"

clear all
use FOIA_pseudo.dta,clear

*For FOIA data, we cannot distinguish major disaster vs general disaster and the applicable collateral threshold is therefore unclear. So we drop the years with two thresholds here: 2014, 2015. 
drop if year==2014| year==2015

gen sample=3 //sample 3: 2014-2020
replace sample=2 if year<=2013 //sample 2: 2008-2013
replace sample=1 if year<=2007 //sample 1: 2003-2007

*generate thresholds
gen threshold=.
replace threshold=10000 if sample==1
replace threshold=14000 if sample==2
replace threshold=25000 if sample==3

*keep a $5,000 loan amount window above and below collateral thresholds
keep if ORIGINAL_APPROVAL_AMOUNT<=65000
gen gap= ORIGINAL_APPROVAL_AMOUNT-threshold
keep if gap>=-5000&gap<=5000
gen buncher=1
replace buncher=0 if gap>500

*generate post secured borrowing dummy. year1 is the secured borrowing year. year is the disaster loan year.
g t=year1-year
g post=0
*we consider a borrower has a post-collateral secured borrowing if there is a secured borroweing record at least two years after borrowing a disaster loan.
replace post=1 if year1>year+1
bysort id: egen post1=max(post)

*cox hazard model
*Identify lenders never borrowed secured debt after disaster loan. (survival groups)
bysort id: replace t=20 if post1==0
*Keep one borrowing record per borrower year
duplicates drop id t,force
stset t, failure(post1)
sts graph, f by(buncher) ylabel(,  nogrid) graphregion(color(white)) title("") xtitle("Years after disaster loan") legend(label(1 "Non-buncher") label(2 "Buncher"))
graph export "Figure 7/fig_postcollateral.pdf", as(pdf) name("Graph") replace

